package jsu.ask.util;

import com.hankcs.hanlp.HanLP;
import com.hankcs.hanlp.seg.Segment;
import com.hankcs.hanlp.seg.common.Term;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class TextParse {

    //疑问词
    //symptom_qwds,cause_qwds,acompany_qwds,food_qwds,drug_qwds
    //prevent_qwds,lasttime_qwds,cureway_qwds,cureprob_qwds,easyget_qwds
    //check_qwds,belong_qwds,cure_qwds
    private static String[] symptom_qwds = {"症状","表征","现象", "症候", "表现"};
    private static String[] cause_qwds = {"原因","成因", "为什么", "怎么会", "怎样才", "咋样才", "怎样会", "如何会", "为啥", "为何", "如何才会", "怎么才会", "会导致", "会造成"};
    private static String[] acompany_qwds = {"并发症", "并发", "一起发生", "一并发生", "一起出现", "一并出现", "一同发生", "一同出现", "伴随发生", "伴随", "共现"};
    private static String[] drug_qwds = {"药", "药品", "用药", "胶囊", "口服液", "炎片"};
    private static String[] food_qwds = {"饮食", "饮用", "吃", "食", "伙食", "膳食", "喝", "菜" ,"忌口", "补品", "保健品", "食谱", "菜谱", "食用", "食物","补品"};
    private static String[] prevent_qwds = {"预防", "防范", "抵制", "抵御", "防止","躲避","逃避","避开","免得","逃开","避开","避掉","躲开","躲掉","绕开","怎样才能不", "怎么才能不", "咋样才能不","咋才能不", "如何才能不","怎样才不", "怎么才不", "咋样才不","咋才不", "如何才不", "怎样才可以不", "怎么才可以不", "咋样才可以不", "咋才可以不", "如何可以不", "怎样才可不", "怎么才可不", "咋样才可不", "咋才可不", "如何可不"};
    private static String[] lasttime_qwds = {"周期", "多久", "多长时间", "多少时间", "几天", "几年", "多少天", "多少小时", "几个小时", "多少年"};
    private static String[] cureway_qwds = {"怎么治疗", "如何医治", "怎么医治", "怎么治", "怎么医", "如何治", "医治方式", "疗法", "咋治", "怎么办", "咋办", "咋治"};
    private static String[] cureprob_qwds = {"多大概率能治好", "多大几率能治好", "治好希望大么", "几率", "几成", "比例", "可能性", "能治", "可治", "可以治", "可以医"};
    private static String[] easyget_qwds = {"易感人群", "容易感染", "易发人群", "什么人", "哪些人", "感染", "染上", "得上"};
    private static String[] check_qwds = {"检查", "检查项目", "查出", "检查", "测出", "试出"};
    private static String[] belong_qwds = {"属于什么科", "属于", "什么科", "科室"};
    private static String[] cure_qwds = {"治疗什么", "治啥", "治疗啥", "医治啥", "治愈啥", "主治啥", "主治什么", "有什么用", "有何用", "用处", "用途", "有什么好处", "有什么益处", "有何益处", "用来", "用来做啥", "用来作甚", "需要", "要"};

//    public static void main(String[] args) {
//        while(true){
//            Scanner sc = new Scanner(System.in);
//            String s = sc.nextLine();
//            List<String> keys = Keys(s);
//            System.out.println(keys);
////            for (String str : keys){
////                System.out.println(str);
////            }
//        }
//
//    }

    public static List<String> Keys(String ques) {
        List<String> key = new ArrayList<String>();
        //nh-医药疾病等健康相关名词; nhd-疾病; nhm-药品; nf-食品; 没有的话查找自定义词典
        Segment segment = HanLP.newSegment().enableCustomDictionary(true);
        System.out.println(segment.seg(ques));
        List<Term> seg = segment.seg(ques);
        for (Term i : seg){
            if(i.nature.toString().equals("nh")){//医药疾病等健康相关名词disease
                key.add(i.word);
                key.add("Disease");
            }else if(i.nature.toString().equals("nhd")){//疾病disease
                key.add(i.word);
                key.add("Disease");
            }else if(i.nature.toString().equals("nhm")){//药品drug
                key.add(i.word);
                key.add("Drug");
            }else if(i.nature.toString().equals("nf")){//食品food
                key.add(i.word);
                key.add("Food");
            }else  if(i.nature.toString().equals("nit")){//科室department
                key.add(i.word);
                key.add("Department");
            }
        }
        //symptom_qwds,cause_qwds,acompany_qwds,food_qwds,drug_qwds
        //prevent_qwds,lasttime_qwds,cureway_qwds,cureprob_qwds,easyget_qwds
        //check_qwds,belong_qwds,cure_qwds
        for (String s : symptom_qwds){//has_symptom关系
            if (ques.contains(s)){
                key.add("has_symptom");
                break;
            }
        }
        for (String s : cause_qwds){//属性
            if (ques.contains(s)){
                key.add("cause");
                break;
            }
        }
        for (String s : acompany_qwds){
            if (ques.contains(s)){
                key.add("acompany_with");
                break;
            }
        }
        for (String s : drug_qwds){
            if (ques.contains(s)){
                key.add("recommand_drug");
                break;
            }
        }
        for (String s : food_qwds){
            if (ques.contains(s)){
                key.add("do_eat");
                break;
            }
        }
        for (String s : prevent_qwds){
            if (ques.contains(s)){
                key.add("prevent");
                break;
            }
        }
        for (String s : lasttime_qwds){
            if (ques.contains(s)){
                key.add("cure_lasttime");
                break;
            }
        }
        for (String s : cureway_qwds){
            if (ques.contains(s)){
                key.add("cure_way");
                break;
            }
        }
        for (String s : cureprob_qwds){
            if (ques.contains(s)){
                key.add("cured_prob");
                break;
            }
        }
        for (String s : easyget_qwds){
            if (ques.contains(s)){
                key.add("easy_get");
                break;
            }
        }
        for (String s : check_qwds){
            if (ques.contains(s)){
                key.add("need_check");
                break;
            }
        }
        for (String s : belong_qwds){
            if (ques.contains(s)){
                key.add("belongs_to");
                break;
            }
        }
        for (String s : cure_qwds){
            if (ques.contains(s)){
                key.add(s);
                break;
            }
        }
        return key;
    }
}

